/*
 * Copyright (c) 2023-2299 深圳市阿毛科技有限公司 All rights reserved.
 *
 * https://www.lamyz.com/
 *
 * 未经允许，不可做商业用途！
 *
 * 版权所有，侵权必究！
 */

package com.lam.mall.api.common.listener;

import java.util.List;

import org.springframework.context.event.EventListener;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import com.google.common.collect.Lists;
import com.lam.mall.api.common.order.ShopCartEventOrder;
import com.lam.mall.app.vo.ShopCartItemDiscountVo;
import com.lam.mall.app.vo.ShopCartItemVo;
import com.lam.mall.app.vo.ShopCartVo;
import com.lam.mall.common.event.ShopCartEvent;

/**
 * 默认的购物车链进行组装时的操作
 */
@Component("defaultShopCartListener")
public class ShopCartListener {

    /**
     * 将店铺下的所有商品归属到该店铺的购物车当中
     * @param event#getShopCart() 购物车
     * @param event#shopCartItemVoList 该购物车的商品
     * @return 是否继续组装
     */
    @EventListener(ShopCartEvent.class)
    @Order(ShopCartEventOrder.DEFAULT)
    public void defaultShopCartEvent(ShopCartEvent event) {
        ShopCartVo shopCart = event.getShopCartVo();
        List<ShopCartItemVo> shopCartItemVoList = event.getShopCartItemVoList();
        // 对数据进行组装
        List<ShopCartItemDiscountVo> shopCartItemDiscountVoList = Lists.newArrayList();
        ShopCartItemDiscountVo shopCartItemDiscountVo = new ShopCartItemDiscountVo();

        shopCartItemDiscountVo.setShopCartItems(shopCartItemVoList);
        shopCartItemDiscountVoList.add(shopCartItemDiscountVo);

        shopCart.setShopCartItemDiscounts(shopCartItemDiscountVoList);
    }

}
